<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>
     <script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
     <link href="${basePath}/css/Huploadify.css" rel="stylesheet">

<style>

table label.error {
    margin-left: 5px;
    width: auto;
    display: inline;
    color: red;
}
</style>


<script type="text/javascript">
//图片上传
var file_path = "prefix";
var file_path_one = null;
var fileMap = new Array();
$(function(){
		var up = $('#uploadadd').Huploadify({
			auto:false,
			fileTypeExts:'*.*',
			multi:true,
			formData:{key:123456,key2:'vvvv'},
			fileSizeLimit:99999999999,
			showUploadedPercent:true,
			showUploadedSize:true,
			removeTimeout:9999999,
			uploader : '${basePath}/twglStudentCadre/source_upload',
			onUploadStart:function(file){
				console.log(file.name+'开始上传');
			},
			onInit:function(obj){
				console.log('初始化');
			},
			onUploadComplete:function(file,data){
				    var fi = $.parseJSON(data);
				    //文件名称
				    var filename = fi.filename;
				    //生成后的文件名
				    var sysFilepath = fi.sysfilepath;
				    //文件路径
				    var filepath = fi.filepath;
				    file_path_one = filename + "," + filepath;
				    file_path = file_path+"|"+filepath;
				    up.filePath=file_path_one;
				    //保存到集合
	                fileMap[file.index]=new Array(file_path_one);
			},
			onCancel:function(file){
				console.log(file.name+'删除成功');
			},
			onClearQueue:function(queueItemCount){
				console.log('有'+queueItemCount+'个文件被删除了');
			},
			onDestroy:function(){
				console.log('destroyed!');
			},
			onSelect:function(file){
				console.log(file.name+'加入上传队列');
			},
			onQueueComplete:function(queueData){
				console.log('队列中的文件全部上传完成',queueData);
			}
		  });	
});

   
//删除图片 
 function deletefile(id){
     	var url = "${basePath}/twglStudentCadre/deletefile";
		$.ajax({
			type : "POST",
			url : url,
			dataType:"json",
			data:{
				filepath : id
			},
			success : function(data) {
				if(data.success == "0000"){
					alert("删除数据成功！");
					var file_name = id.split(",")[0];
					
					$("#"+file_name+"_hr").parent().parent().remove();
				}else{
					alert("未写入数据库的文件没有删除！请联系管理员！");
				}
			}
		})
   } 
</script>	

<script>
$(document).ready(
					function() {
						$("#div1").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择学生',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							
							  if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
								 alert("请选择一项");
								 return false;
							  }else{
								    var formSelect = document.getElementById("fromSelect");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 5});
								      return false;
								    }else{
								    	var result = $.parseJSON('${studentListJson}');
								    	var xsid=$("#fromSelect").val();
										for (var i = 0; i < result.length; i++) {
											if(xsid==result[i].xsid){
										     $("#stuid").val(result[i].xsid);	
											 $("#xh").val(result[i].xh);
											 $("#xm").val(result[i].xm);
											 $("#xb").val(result[i].xb);
											 $("#bjmc").val(result[i].bjmc);
											 $("#zymc").val(result[i].zymc);
											 $("#njmc").val(result[i].njmc);
											 break;
											}
										}
										 $(this).dialog('close');
								    }
								    
							  }
							  
							}
						  }
						});
						
						
						
						
						$("#divstu").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择学生',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							
							  if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
								 alert("请选择一项");
								 return false;
							  }else{
								    var formSelect = document.getElementById("fromSelectStu");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 5});
								      return false;
								    }else{
								    	 $("#auditorname").val($("#fromSelectStu").find("option:selected").text()); 
										 $("#auditorid").val($("#fromSelectStu").val());
										 $(this).dialog('close');
								    }
								    
							  }
							  
							}
						  }
						});
						
						
						
						$("#divTeachers").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择老师',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							
							  if($("#fromSelectTeachers").val()==null||$("#fromSelectTeachers").val()==""){
								 alert("请选择一项");
								 return false;
							  }else{
								    var formSelect = document.getElementById("fromSelectTeachers");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 5});
								      return false;
								    }else{
								    	 $("#auditorname").val($("#fromSelectTeachers").find("option:selected").text()); 
										 $("#auditorid").val($("#fromSelectTeachers").val());
										 $(this).dialog('close');
								    }
								    
							  }
							  
							}
						  }
						});
						

					});
	function showdiv() {
		$('#div1').dialog('open');
	}
	
	
	function showdivstu() {
		 var val = $('input:radio[name="auditortype"]:checked').val();
         if(val == 2) {
        	 $('#divstu').dialog('open');
         } else {
        	 $('#divTeachers').dialog('open');
         }
	}
</script>



</head>
<body>
     <form action="#" name="Form" id="Form" method="post">
        <input type="hidden" name="gbid" id="gbid"  value="${data.gbid}"/>
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="95%" >
			<tr>
				<td class="table-header" colspan="4">学生干部信息</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>姓名:</td>
				<td class="table-contentTD" style="width: 35%">
				<input type="hidden" name="stuid" id="stuid"  value="${data.stuid}"/>
				<input type="text" id="xm" name="xm" placeholder="姓名"    value="${data.xm}"  readonly="readonly"  style="width: 92%" class="required inputText" />
				<input type="button" value="选择" class="inputButton" onclick="javascript:showdiv();" />
				</td>
		
		      <td class="table-titleTD" style="width: 15%">学号:</td>
				<td class="table-contentTD">
				<input type="text" name="xh" id="xh" placeholder="学号"    value="${data.xh}"  class="inputText"  readonly="readonly"  autocomplete="off"/></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">性别:</td>
			    <td class="table-contentTD">
				<input type="text" id="xb" name="xb" placeholder="性别"   readonly="readonly"    value="${data.xb}"   class="inputText" /></td>
		
			    <td class="table-titleTD" style="width: 15%">班级名称:</td>
				<td class="table-contentTD">
				<input type="text" name="bjmc" id="bjmc" placeholder="班级名称"    value="${data.bjmc}"   class="inputText"  readonly="readonly"  autocomplete="off"/></td>
			</tr>
		  <tr>
				<td class="table-titleTD" style="width: 15%">专业:</td>
			    <td class="table-contentTD">
				<input type="text" id="zymc" name="zymc" placeholder="专业"    value="${data.zymc}"    readonly="readonly"   class="inputText" /></td>
				
			    <td class="table-titleTD" style="width: 15%">年级:</td>
				<td class="table-contentTD">
				<input type="text" name="njmc" id="njmc" placeholder="年级"     value="${data.njmc}"  class="inputText"  readonly="readonly"  autocomplete="off"/></td>
			</tr>
			
			<tr>
				<td class="table-titleTD" style="width: 15%">职务:</td>
				<td class="table-contentTD">
			  	<input type="text" name="drzw" id="drzw" placeholder="职务"   value="${data.drzw}"   class="inputText"  autocomplete="off"/></td>
				<!-- <select id="drzw" name="drzw" class="selectList required"  style="width:36%">
						<option value="">请选择</option>
						<option value="1">主席</option>
						<option value="2">副主席过</option>
						<option value="3">部长</option>
						<option value="3">干事</option>
				</select>  --></td>
				<td class="table-titleTD" style="width: 15%">担任开始日期:</td>
				<td class="table-contentTD">
				<input name="ksrq1" id="ksrq1" placeholder="担任开始日期"   autocomplete="off"   value="${data.ksrq1}"  
									class="Wdate text inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})"/></td>
			</tr>
		   
		   
			 <tr>
				<td class="table-titleTD" style="width: 15%">担任年限:</td>
			    <td class="table-contentTD">
				<input type="number" id="rznx" name="rznx" placeholder="担任年限"   value="${data.rznx}"   maxlength="8" class="inputText" /></td>
				
				<td class="table-titleTD" style="width: 15%">状态：</td>
				<td class="table-contentTD">
				<select id="states" name="states" class="selectList" >
					   <option value="0">未提交</option>
				<!-- 	<option value="1">审核中</option>
						<option value="2">审核通过</option>
						<option value="3">审核退回</option>  -->
				</select></td>
			</tr>
			 <tr>
				<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>递交对象：</td>
				<td class="table-contentTD">
					   <input type="radio" value="2" name="auditortype" <c:if test="${data.auditortype==2}">checked="checked"</c:if> />学生
					   <input type="radio" value="1" name="auditortype" <c:if test="${data.auditortype==1}">checked="checked"</c:if> />老师
				</td>
				
				<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>递交给:</td>
				<td class="table-contentTD">
			     <input type="hidden" name="auditorid" id="auditorid" value="${data.auditorid}" />
				<input type="text" id="auditorname" name="auditorname" placeholder="递交给" value="${data.auditorname}"  style="width: 92%"  readonly="readonly"   class="required inputText" />
				<input type="button" id="butstu"  value="选择" class="inputButton" onclick="javascript:showdivstu();" />
				</td>
				
			</tr>
		     <tr>
						 <td class="table-titleTD" style="width: 15%">附件</td>
						 <td class="table-contentTD" colspan="3">
						      <table>
						            <tr>
						               <td colspan="2">
						                  <div id="uploadadd"></div>
						                </td>
						            </tr>
						         
						           <c:forEach items="${dataList}" var="datalist" varStatus="index">
							           <tr>
						                    <td>
									            [文件] ${datalist.filename}
									         </td>
									         <td>
									               <a href="${basePath}/DownLoadFileServlet?filename=${datalist.filename}&filepath=${datalist.filepath}">下载</a> 
									               <button id="${datalist.gid}_hr" type="button"  onclick="deleteByPK('${datalist.gid}');">删除</button>
					                          </td>
						                </tr>
							   	    </c:forEach>
							   </table>
						 </td>
			</tr>
			
			<tr>
				<td class="table-titleTD">备注：</td>
				<td class="table-contentTD" colspan="3"><textarea style="width: 90%;height: 80px;" name="remark"  placeholder="备注" id="remark" maxlength="2000" >${data.remark}</textarea></td>
			</tr>
		</table>
	 </form>
		<br />
		
		
		
		  <div id="div1" style="display: none;">
				<table cellpadding="0" cellspacing="0" border="0" class="table-border">
					  <tr>
						  	 <td style="clear:both; width: 70%">
						  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
						  	   <br/><label style="color:red;">未选中:</label><br/>
						  	   <select name="fromSelect" id="fromSelect" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
									ondblclick="moveField('fromSelect','toSelect');">
													<c:forEach items="${studentList}" var="data">
									       <option value="${data.xsid}">${data.xm}</option>
								          </c:forEach>
								</select>
									<select name="sourseFromSelect2" id="sourseFromSelect2"   multiple="false" style="width: 220px; height: 150px; display: none;" >
													<c:forEach items="${studentList}" var="data">
									                 <option value="${data.xsid}">${data.xm}</option>
								                    </c:forEach>
		  	                        </select>
							  </td>
	  	              </tr>
				</table>
		    </div>
		 
		 
		    <div id="divstu" style="display: none;">
				<table cellpadding="0" cellspacing="0" border="0" class="table-border">
					  <tr>
						  	 <td style="clear:both; width: 70%">
						  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2Stu','fromSelectStu','fromSelectStu',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2Stu','fromSelectStu','fromSelectStu',this.value);"/><font color="green">在此查找</font> <br/>
						  	   <br/><label style="color:red;">未选中:</label><br/>
						  	   <select name="fromSelectStu" id="fromSelectStu" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
									ondblclick="moveField('fromSelectStu','toSelect');">
													<c:forEach items="${studentList}" var="data">
									       <option value="${data.xsid}">${data.xm}</option>
								          </c:forEach>
								</select>
									<select name="sourseFromSelect2Stu" id="sourseFromSelect2Stu"   multiple="false" style="width: 220px; height: 150px; display: none;" >
													<c:forEach items="${studentList}" var="data">
									                 <option value="${data.xsid}">${data.xm}</option>
								                    </c:forEach>
		  	                        </select>
							  </td>
	  	              </tr>
				</table>
		   </div>
		 
		 
		   <div id="divTeachers" style="display: none;">
				<table cellpadding="0" cellspacing="0" border="0" class="table-border">
					  <tr>
						  	 <td style="clear:both; width: 70%">
						  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2Teachers','fromSelectTeachers','fromSelectTeachers',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2Teachers','fromSelectTeachers','fromSelectTeachers',this.value);"/><font color="green">在此查找</font> <br/>
						  	   <br/><label style="color:red;">未选中:</label><br/>
						  	   <select name="fromSelectTeachers" id="fromSelectTeachers" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
									ondblclick="moveField('fromSelectTeachers','toSelect');">
													<c:forEach items="${EmployeeList}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach>
								</select>
									<select name="sourseFromSelect2Teachers" id="sourseFromSelect2Teachers"   multiple="false" style="width: 220px; height: 150px; display: none;" >
													<c:forEach items="${EmployeeList}" var="data">
									                     <option value="${data.emid}">${data.xm}</option>
								                    </c:forEach>
		  	                        </select>
							  </td>
	  	              </tr>
				</table>
		    </div>
		    
		    
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
			    <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"TWGL_XSGB_XSGBSQ\")%>" key="modify">		
			    <td><input type="button" id="btnSave" class="inputButton" style="text-align: center;" value="保存" /></td>
			    </kl:permission>
				<td><input type="button" id="Cancel" class="inputButton" style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton" value="返回" style="text-align: center;" /></td>
			</tr>
		</table>
		
		<script>
			$(document).ready(function() {
				var _form=$("#Form").validate();
				$("#btnSave").click(function() {
					if(_form.form()){
						  validateObj();
					}
				});
				
				
				function validateObj(){
				  	/* $.ajax({
						  type: 'POST',
						  url: "${basePath}/bjxxClassWorkInstead/validation",
					      data:{xmmc : $('#xmmc').val(),id:$('#xmid').val()},
						  success:function(data){
						   if(data.msg=="-99"){
							     layer.alert('服务器异常', {icon: 5});
							     return false;
						   }else if(data.msg!='0'){
							     layer.alert('项目名称已经存在请重新输入', {icon: 5});
							     return false;
						   }else{ */
							    document.Form.action ="${basePath}/twglStudentCadre/update";
								document.Form.submit();
						  /*  }   
						  }
						});	 */
				}
				
			/* 	$("#updatebtnSubmit").click(function() {
					  document.Form.action ="${basePath}/twglStudentCadre/updatebtnSubmit";
				      document.Form.submit();
		 		}); */
				
				
				
				$("#Cancel").click(function() {
					   window.location.href ="${basePath}/twglStudentCadre/details?id="+ $("#gbid").val();
		 		});
				
				$("#returnBut").click(function() {
		 			 window.location.href='${basePath}/twglStudentCadre/index';
		 		});
				
				
				
				//已有的数据进行删除操作
				function deleteByPK(id){
					var action = "${basePath}/twglStudentCadre/source_upload_update";
				    layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
							$.ajax({
								type : "POST",
								url : action,
								dataType:"json",
								data:{
									 id : id
								},
								success : function(data) {
									if(data.success == "0000"){
										layer.alert('删除数据成功', {icon: 6});
										$("#"+id+"_hr").parent().parent().remove();
									}else{
										layer.alert('未写入数据库的文件没有删除！请联系管理员！', {icon: 5});
									}
								}
							})
					 },function(index){
					    layer.close(index);
				     });
			      }
			});
		</script>
</body>
</html>
